home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / canvas.h < prev    next >
C/C++ Source or Header  |  2001-10-08  |  9KB  |  372 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. //NONPORTABLE: the interface is portable, but the implementation sure isn't
  30. #ifndef _CANVAS_H
  31. #define _CANVAS_H
  32.  
  33. #include <ddraw.h>
  34. #include "common.h"
  35.  
  36. class Canvas;
  37. class MemCanvasBmp;
  38. class BaseWnd;
  39. class RootWnd;
  40. class Region;
  41. class SkinBitmap;
  42.  
  43. #include "stack.h"
  44. #include "ptrlist.h"
  45. #include "string.h"
  46.  
  47. #include "dispatch.h"
  48.  
  49. // abstract base class: safe to use in API
  50. class COMEXP NOVTABLE CanvasBase : public Dispatchable {
  51. protected:
  52.   CanvasBase() {} // protect constructor
  53.  
  54. public:
  55.   HDC getHDC() {
  56.     return _call(GETHDC, (HDC)0);
  57.   }
  58.   RootWnd *getRootWnd() {
  59.     return _call(GETROOTWND, (RootWnd*)0);
  60.   }
  61.   void *getBits() {
  62.     return _call(GETBITS, (void *)0);
  63.   }
  64.   void getOffsets(int *x, int *y) {
  65.     _voidcall(GETOFFSETS, x, y);
  66.   }
  67.   BOOL isFixedCoords() {//FG> allows onPaint to handle double buffers as well as normal DCs
  68.     return _call(ISFIXEDCOORDS, FALSE);
  69.   }
  70.   BOOL getDim(int *w, int *h, int *p) { // w & h in pixels, pitch in bytes. 0 on success. 
  71.     return _call(GETDIM, FALSE, w, h, p);
  72.   }
  73.  
  74.   const char *getTextFont() {
  75.     return _call(GETTEXTFONT, "");
  76.   }
  77.   int getTextSize() {
  78.     return _call(GETTEXTSIZE, -1);
  79.   }
  80.   int getTextBold() {
  81.     return _call(GETTEXTBOLD, -1);
  82.   }
  83.   int getTextOpaque() {
  84.     return _call(GETTEXTOPAQUE, -1);
  85.   }
  86.   int getTextAlign() {
  87.     return _call(GETTEXTALIGN, -1);
  88.   }
  89.   COLORREF getTextColor() {
  90.     return _call(GETTEXTCOLOR, RGB(0,0,0));
  91.   }
  92.  
  93.   enum {
  94.     GETHDC        = 100,
  95.     GETROOTWND        = 200,
  96.     GETBITS        = 300,
  97.     GETOFFSETS        = 400,
  98.     ISFIXEDCOORDS    = 500,
  99.     GETDIM        = 600,
  100.     GETTEXTFONT        = 700,
  101.     GETTEXTSIZE        = 710,
  102.     GETTEXTBOLD        = 720,
  103.     GETTEXTOPAQUE    = 730,
  104.     GETTEXTALIGN    = 740,
  105.     GETTEXTCOLOR    = 750,
  106.   };
  107. };
  108.  
  109. class COMEXP NOVTABLE Canvas : public CanvasBase {
  110. protected:
  111.   Canvas();
  112. public:
  113.   virtual ~Canvas();
  114.  
  115. // CanvasBase stuff
  116.   HDC getHDC();
  117.   RootWnd *getRootWnd();
  118.   void *getBits();
  119.   void getOffsets(int *x, int *y);
  120.   BOOL isFixedCoords();
  121.   BOOL getDim(int *w, int *h, int *p);
  122.   void setBaseWnd(BaseWnd *b);
  123. // end CanvasBase stuff
  124.  
  125.   virtual BaseWnd *getBaseWnd();
  126.  
  127.   // graphics commands
  128.   void fillRect(RECT *r, COLORREF color);
  129.   void drawRect(RECT *r, int solid, COLORREF color);
  130.  
  131.   // text commands
  132.   void setTextFont(const char *font_id_name);
  133.   const char *getTextFont();
  134.   void pushTextFont(const char *font_id_name);
  135.   const char *popTextFont();
  136.  
  137.   void setTextSize(int points);
  138.   int getTextSize();
  139.   void pushTextSize(int points);
  140.   int popTextSize();
  141.  
  142.   void setTextBold(int bold);
  143.   int getTextBold();
  144.   void pushTextBold(int bold);
  145.   int popTextBold();
  146.  
  147.   void setTextOpaque(int op);
  148.   int getTextOpaque();
  149.   void pushTextOpaque(int op);
  150.   int popTextOpaque();
  151.  
  152.   void setTextAlign(int al);
  153.   int getTextAlign();
  154.   void pushTextAlign(int al);
  155.   int popTextAlign();
  156.  
  157.   void setTextColor(COLORREF color);
  158.   COLORREF getTextColor();
  159.   void pushTextColor(COLORREF color);
  160.   COLORREF popTextColor();
  161.  
  162.   // normal text
  163.   void textOut(int x, int y, const char *txt);
  164.   void textOut(int x, int y, int w, int h, const char *txt);
  165.   void textOutEllipsed(int x, int y, int w, int h, const char *txt);
  166.   // returns height used
  167.   void textOutWrapped(int x, int y, int w, int h, const char *txt);
  168.   void textOutWrappedPathed(int x, int y, int w, const char *txt);
  169.   void textOutCentered(RECT *r, const char *txt);
  170.  
  171.   int getTextWidth(const char *text);
  172.   int getTextHeight(const char *text);
  173.   void getTextExtent(const char *text, int *w, int *h);
  174.   int getTextHeight() { return getTextHeight("M"); }
  175.   void selectClipRgn(Region *r);
  176.   int getClipBox(RECT *r); // returns 0 if no clipping region
  177.   int getClipRgn(Region *r); // returns 0 if no clipping region
  178.  
  179.   void moveTo(int x, int y);
  180.   void lineTo(int x, int y);
  181.  
  182.   void blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
  183.   
  184.   // src* are in 16.16 fixed point
  185.   void stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
  186.  
  187.   void antiAliasTo(Canvas *dest, int w, int h, int aafactor);
  188.  
  189.   int getXOffset() const { return xoffset; }
  190.   int getYOffset() const { return yoffset; }
  191.   void offsetRect(RECT *r);
  192.   void debug();
  193.  
  194. protected:
  195.   virtual int _dispatch(int msg, void *retval, void **params=NULL, int nparam=0);
  196.  
  197.   HDC hdc;
  198.   void *bits;
  199.   int width, height, pitch;
  200.   BOOL fcoord;
  201.   int xoffset, yoffset;
  202.   BaseWnd *srcwnd;
  203.  
  204. private:
  205.   Stack<String*> fontstack;
  206.   Stack<COLORREF> colorstack;
  207.   Stack<int> boldstack;
  208. //  Stack<int> varstack;
  209.   Stack<int> opstack;
  210.   Stack<int> alstack;
  211.   Stack<int> sizestack;
  212.  
  213. /*  HFONT makeFont(int size, const char *fontfacename=NULL, int bold=FALSE);
  214.   void deleteFont(HFONT font);*/
  215.  
  216.   int tsize;
  217.   int align;
  218.   int tbold;
  219.   int topaque;
  220. //  int tvariable;
  221.   COLORREF tcolor;
  222.   String *tfont;
  223.  
  224.   static char retfontname[256];
  225. };
  226.  
  227. class COMEXP WndCanvas : public Canvas {
  228. public:
  229.   WndCanvas();
  230.   virtual ~WndCanvas();
  231.  
  232.   // address client area
  233.   int attachToClient(BaseWnd *basewnd);
  234. //CUT  // address entire window
  235. //CUT  int attachToWnd(HWND _hWnd);    // NONPORTABLE: avoid! mostly for mainwnd
  236.   
  237. private:
  238.   HWND hWnd;
  239. };
  240.  
  241. class COMEXP PaintCanvas : public Canvas {
  242. public:
  243.   PaintCanvas();
  244.   virtual ~PaintCanvas();
  245.  
  246.   int beginPaint(BaseWnd *basewnd);
  247.   void getRcPaint(RECT *r);
  248.  
  249. private:    // NONPORTABLE
  250.   HWND hWnd;
  251.   PAINTSTRUCT ps;
  252. };
  253.  
  254. class COMEXP PaintBltCanvas : public Canvas {
  255. public:
  256.   PaintBltCanvas();
  257.   virtual ~PaintBltCanvas();
  258.   int beginPaint(BaseWnd *basewnd);
  259.   int beginPaintNC(BaseWnd *basewnd);
  260.  
  261.   void *getBits();
  262.   void getRcPaint(RECT *r);
  263.  
  264. private:    // NONPORTABLE
  265.   HWND hWnd;
  266.   PAINTSTRUCT ps;
  267.   HDC wnddc;
  268.   HBITMAP hbmp, prevbmp;
  269.   BOOL nonclient;
  270. };
  271.  
  272. class COMEXP MemCanvas : public Canvas {
  273. public:
  274.   MemCanvas();
  275.   virtual ~MemCanvas();
  276.  
  277.   int createCompatible(Canvas *canvas);
  278. private:
  279. };
  280.  
  281. class COMEXP DCCanvas : public Canvas {
  282. public:
  283.   DCCanvas(HDC clone=NULL, BaseWnd *srcWnd=NULL);
  284.   virtual ~DCCanvas();
  285.  
  286.   int cloneDC(HDC clone, BaseWnd *srcWnd=NULL);
  287. };
  288.  
  289. class COMEXP SysCanvas : public Canvas {
  290. public:
  291.   SysCanvas();
  292.   virtual ~SysCanvas();
  293. };
  294.  
  295. class COMEXP DCBltCanvas : public Canvas {
  296. public:
  297.   DCBltCanvas();
  298.   virtual ~DCBltCanvas();
  299.  
  300.   int cloneDC(HDC clone, RECT *r, BaseWnd *srcWnd=NULL);
  301.   int setOrigDC(HDC neworigdc); // set to null to prevent commitdc on delete, non null to change destination dc
  302.   int commitDC(void);                        // allows commit to DC without deleting
  303. #if 0
  304.   int cloneCanvas(CanvasBase *clone, RECT *r);
  305. #endif
  306.  
  307. private:
  308.   HDC origdc;
  309.   RECT rect;
  310.   HBITMAP hbmp, prevbmp;
  311. };
  312.  
  313. // note: getBaseWnd() returns NULL for this class
  314. class COMEXP BaseCloneCanvas : public Canvas {
  315. public:
  316.   BaseCloneCanvas(CanvasBase *cloner=NULL);
  317.   virtual ~BaseCloneCanvas();
  318.  
  319.   int clone(CanvasBase *cloner);
  320. };
  321.  
  322. class COMEXP BltCanvas : public Canvas {
  323. public:
  324.   BltCanvas(int w, int h, int nb_bpp=32, unsigned char *pal=NULL,int palsize=0);
  325.   BltCanvas(HBITMAP bmp);
  326.   virtual ~BltCanvas();
  327.   void *getBits();
  328.   HBITMAP getBitmap();
  329.   SkinBitmap *makeSkinBitmap(); // this one makes a new, with own bits
  330.   SkinBitmap *getSkinBitmap(); // this one gives a skinbitmap envoloppe of this bltcanvas
  331.   void disposeSkinBitmap(SkinBitmap *b); // call only after makeSkinBitmap
  332.  
  333.   void fillBits(COLORREF color);
  334.  
  335.   void vflip();
  336.   void maskColor(COLORREF from, COLORREF to);
  337.  
  338. private:    // NONPORTABLE
  339.   HBITMAP hbmp, prevbmp;
  340.   PtrList<SkinBitmap> *skinbmps;
  341.   SkinBitmap *envelope;
  342.   BITMAP bm;
  343.   BOOL ourbmp;
  344.   int bpp;
  345. };
  346.  
  347. class COMEXP DDSurfaceCanvas : public Canvas {
  348.  
  349. public:
  350.  
  351.   DDSurfaceCanvas(LPDIRECTDRAWSURFACE surface, int w, int h);
  352.   virtual ~DDSurfaceCanvas();
  353.  
  354.   int isready();
  355.   void enter();
  356.   void exit();
  357.  
  358. private:
  359.  
  360.   LPDIRECTDRAWSURFACE surf;
  361.   int _w, _h;
  362. };
  363.  
  364. enum
  365. {
  366.     ALIGN_LEFT,
  367.     ALIGN_CENTER,
  368.     ALIGN_RIGHT
  369. };
  370.  
  371. #endif
  372.